<template>
  <div class="patient-list">
    <div
      v-for="patient in patients"
      :key="patient.id"
      class="patient-item"
      :class="{
        active: currentPatient?.id === patient.id,
        treating: patient.status === '就诊中'
      }"
      @click="onPatientSelect(patient)"
    >
      <div class="patient-avatar">
        {{ patient.gender === '男' ? '👨' : '👩' }}
      </div>
      <div class="patient-info">
        <div class="patient-basic">
          <span class="patient-name">{{ patient.name }}</span>
          <span class="patient-gender-age">{{ patient.gender }} {{ patient.age }}岁</span>
        </div>
      </div>
      <div class="patient-status" :class="patient.status === '就诊中' ? 'treating' : 'waiting'">
        {{ patient.status }}
      </div>
    </div>
  </div>
</template>

<script setup>
const props = defineProps({
  // 接收父组件传递的病人列表
  patients: {
    type: Array,
    required: true,
    default: () => []
  },
  // 接收父组件传递的当前选中病人
  currentPatient: {
    type: Object,
    required: false
  }
})

// 定义要触发的事件
const emit = defineEmits(['patient-select'])

// 当病人项被点击时，触发事件并将病人数据传递给父组件
const onPatientSelect = (patient) => {
  emit('patient-select', patient)
}
</script>

<style scoped>
.patient-card {
  background: white;
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(10px);
  transition: all 0.3s ease;
  height: 100%;
  display: flex;
  flex-direction: column;
}
.card-header {
  display: flex;
  align-items: center;
  padding: 20px 24px 16px;
  border-bottom: 1px solid #f0f2f5;
}
.card-title {
  font-size: 18px;
  font-weight: 600;
  color: #1a1a1a;
  margin-left: 10px;
}
.card-header i {
  font-size: 20px;
  color: #4a6cf7;
}
.patient-count {
  margin-left: auto;
  background: #4a6cf7;
  color: white;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
}
.patient-list {
  flex: 1;
  overflow-y: auto;
  max-height: 700px;
  padding: 8px 0;
}
.patient-item {
  display: flex;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid #f0f2f5;
  cursor: pointer;
  transition: all 0.3s;
  position: relative;
}
.patient-item:hover:not(.disabled) {
  background: #f8f9fc;
}
.patient-item.active {
  background: linear-gradient(135deg, rgba(74, 108, 247, 0.08), rgba(108, 138, 255, 0.04));
  border-left: 4px solid #4a6cf7;
}
.patient-item.treating {
  background: linear-gradient(135deg, rgba(255, 107, 107, 0.08), rgba(255, 143, 143, 0.04));
}
.patient-avatar {
  font-size: 32px;
  margin-right: 16px;
}
.patient-info {
  flex: 1;
}
.patient-basic {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}
.patient-name {
  font-weight: 600;
  color: #1a1a1a;
  font-size: 16px;
}
.patient-gender-age {
  color: #8f9bb3;
  font-size: 14px;
}
.patient-diagnosis {
  color: #4a6cf7;
  font-weight: 500;
  font-size: 14px;
}
.patient-status {
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.patient-status.treating {
  background: #ff6b6b;
  color: white;
}
.patient-status.waiting {
  background: #ffd166;
  color: #8a6500;
}
/* 滚动条样式 */
.patient-list::-webkit-scrollbar {
  width: 6px;
}
.patient-list::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}
.patient-list::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}
.patient-list::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}
</style>